package com.whatever;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

public class NotificationPracticeActivity extends Activity {
    
	private final static int NOTIFY_ME_ID = 1337;
	private Timer timer = new Timer();
	private int count = 0;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button button0 = (Button)findViewById(R.id.button0);
        Button button1 = (Button)findViewById(R.id.button1);
        
        button0.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		TimerTask task = new TimerTask() {
        			public void run() {
        				notifyMe();
        			}
        		};
        		timer.schedule(task, 5000);
        	}
        });
        
        button1.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        	}
        });
    }
    
    public void notifyMe() {
    	final NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    	Notification note = new Notification(R.drawable.happyohstopityoullarge, "Status Message!", System.currentTimeMillis());
    	PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this, NotificationPracticeActivity.class), 0);
    	note.setLatestEventInfo(this, "Notification Title", "This is a notification!", i);
    	note.number = ++count;
    	note.defaults |= Notification.DEFAULT_SOUND;
    	//note.defaults |= Notification.DEFAULT_VIBRATE;
    	manager.notify(NOTIFY_ME_ID, note);
    }
}	